<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>mysql学习第一天 | 凌歆的博客</title>
    <meta name="generator" content="VuePress 1.9.5">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="web前端技术博客,专注web前端学习与总结。JavaScript,js,ES6,TypeScript,vue,React,python,css3,html5,Node,git,github等技术文章。">
    <meta name="keywords" content="前端博客,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown">
    <meta name="baidu-site-verification" content="7F55weZDDc">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.d9c8cf8c.css" as="style"><link rel="preload" href="/assets/js/app.57550e13.js" as="script"><link rel="preload" href="/assets/js/2.f014c35f.js" as="script"><link rel="preload" href="/assets/js/91.a661f52d.js" as="script"><link rel="prefetch" href="/assets/js/10.03a98811.js"><link rel="prefetch" href="/assets/js/100.145e708e.js"><link rel="prefetch" href="/assets/js/101.098ca5c8.js"><link rel="prefetch" href="/assets/js/102.4d45c69a.js"><link rel="prefetch" href="/assets/js/103.499de505.js"><link rel="prefetch" href="/assets/js/104.c2c1b9b6.js"><link rel="prefetch" href="/assets/js/105.4e9b0663.js"><link rel="prefetch" href="/assets/js/106.9bb8cf6f.js"><link rel="prefetch" href="/assets/js/107.a81b32d7.js"><link rel="prefetch" href="/assets/js/108.81511e67.js"><link rel="prefetch" href="/assets/js/109.6a6741bf.js"><link rel="prefetch" href="/assets/js/11.e8729182.js"><link rel="prefetch" href="/assets/js/110.de657fe7.js"><link rel="prefetch" href="/assets/js/111.b092af6d.js"><link rel="prefetch" href="/assets/js/112.2dca5709.js"><link rel="prefetch" href="/assets/js/113.dbed1fac.js"><link rel="prefetch" href="/assets/js/114.e95a0131.js"><link rel="prefetch" href="/assets/js/115.2e3e8285.js"><link rel="prefetch" href="/assets/js/116.e64f7fec.js"><link rel="prefetch" href="/assets/js/117.583552c9.js"><link rel="prefetch" href="/assets/js/118.aa5d18f0.js"><link rel="prefetch" href="/assets/js/119.0c7b52d7.js"><link rel="prefetch" href="/assets/js/12.d63acec2.js"><link rel="prefetch" href="/assets/js/120.13f86281.js"><link rel="prefetch" href="/assets/js/121.e2b5b7f9.js"><link rel="prefetch" href="/assets/js/122.5252216a.js"><link rel="prefetch" href="/assets/js/123.8b8a3503.js"><link rel="prefetch" href="/assets/js/124.60df855c.js"><link rel="prefetch" href="/assets/js/125.f073ab1c.js"><link rel="prefetch" href="/assets/js/126.7b73de6a.js"><link rel="prefetch" href="/assets/js/127.4e25971c.js"><link rel="prefetch" href="/assets/js/128.0edf0e06.js"><link rel="prefetch" href="/assets/js/129.5cb5a70a.js"><link rel="prefetch" href="/assets/js/13.2259ef71.js"><link rel="prefetch" href="/assets/js/130.00247fda.js"><link rel="prefetch" href="/assets/js/131.d6fc003a.js"><link rel="prefetch" href="/assets/js/132.1a32b18f.js"><link rel="prefetch" href="/assets/js/133.e46c0193.js"><link rel="prefetch" href="/assets/js/134.a6ad681f.js"><link rel="prefetch" href="/assets/js/135.2fcbe137.js"><link rel="prefetch" href="/assets/js/136.f69bf451.js"><link rel="prefetch" href="/assets/js/137.b9ef2fcc.js"><link rel="prefetch" href="/assets/js/138.7fdd9feb.js"><link rel="prefetch" href="/assets/js/139.a3a37c91.js"><link rel="prefetch" href="/assets/js/14.0d6b23b9.js"><link rel="prefetch" href="/assets/js/140.a7c013ae.js"><link rel="prefetch" href="/assets/js/141.956c36ce.js"><link rel="prefetch" href="/assets/js/142.5aacfe42.js"><link rel="prefetch" href="/assets/js/143.57d691ef.js"><link rel="prefetch" href="/assets/js/144.b1e5766e.js"><link rel="prefetch" href="/assets/js/145.463284b7.js"><link rel="prefetch" href="/assets/js/146.6cc6420c.js"><link rel="prefetch" href="/assets/js/147.5b78c5a2.js"><link rel="prefetch" href="/assets/js/148.8d1d7679.js"><link rel="prefetch" href="/assets/js/149.4e0eb213.js"><link rel="prefetch" href="/assets/js/15.f6fde69d.js"><link rel="prefetch" href="/assets/js/150.b183de37.js"><link rel="prefetch" href="/assets/js/151.729ae770.js"><link rel="prefetch" href="/assets/js/152.b1297018.js"><link rel="prefetch" href="/assets/js/153.bb991bca.js"><link rel="prefetch" href="/assets/js/154.6f2286aa.js"><link rel="prefetch" href="/assets/js/155.6a9c7e4d.js"><link rel="prefetch" href="/assets/js/156.f7bd535d.js"><link rel="prefetch" href="/assets/js/157.64c0065c.js"><link rel="prefetch" href="/assets/js/158.d31ae949.js"><link rel="prefetch" href="/assets/js/159.7daea8a7.js"><link rel="prefetch" href="/assets/js/16.7be21beb.js"><link rel="prefetch" href="/assets/js/160.33cc971a.js"><link rel="prefetch" href="/assets/js/161.1676442a.js"><link rel="prefetch" href="/assets/js/162.71378046.js"><link rel="prefetch" href="/assets/js/163.99e49959.js"><link rel="prefetch" href="/assets/js/164.306f07d2.js"><link rel="prefetch" href="/assets/js/165.170977c7.js"><link rel="prefetch" href="/assets/js/166.f8602525.js"><link rel="prefetch" href="/assets/js/167.eea5c001.js"><link rel="prefetch" href="/assets/js/168.0146a311.js"><link rel="prefetch" href="/assets/js/169.05f9c9d9.js"><link rel="prefetch" href="/assets/js/17.2543f471.js"><link rel="prefetch" href="/assets/js/170.25d602b2.js"><link rel="prefetch" href="/assets/js/171.1ada26a6.js"><link rel="prefetch" href="/assets/js/172.2a0f697c.js"><link rel="prefetch" href="/assets/js/173.230d8ca8.js"><link rel="prefetch" href="/assets/js/174.e3758a2b.js"><link rel="prefetch" href="/assets/js/175.0f19f8ea.js"><link rel="prefetch" href="/assets/js/176.bf70d37d.js"><link rel="prefetch" href="/assets/js/177.4400f272.js"><link rel="prefetch" href="/assets/js/178.85af7b89.js"><link rel="prefetch" href="/assets/js/179.4cfaaaa2.js"><link rel="prefetch" href="/assets/js/18.394415f8.js"><link rel="prefetch" href="/assets/js/180.449c8409.js"><link rel="prefetch" href="/assets/js/181.73276924.js"><link rel="prefetch" href="/assets/js/182.5fab25cc.js"><link rel="prefetch" href="/assets/js/183.ecd4934d.js"><link rel="prefetch" href="/assets/js/184.246092cf.js"><link rel="prefetch" href="/assets/js/185.c671cd86.js"><link rel="prefetch" href="/assets/js/186.49bd1963.js"><link rel="prefetch" href="/assets/js/187.1fb32764.js"><link rel="prefetch" href="/assets/js/188.7c6885e9.js"><link rel="prefetch" href="/assets/js/189.a8701dec.js"><link rel="prefetch" href="/assets/js/19.ca7db8ea.js"><link rel="prefetch" href="/assets/js/190.ae3d3bde.js"><link rel="prefetch" href="/assets/js/191.ad7cd44e.js"><link rel="prefetch" href="/assets/js/192.bc443842.js"><link rel="prefetch" href="/assets/js/193.e4755764.js"><link rel="prefetch" href="/assets/js/194.814112ce.js"><link rel="prefetch" href="/assets/js/195.1c0aaa80.js"><link rel="prefetch" href="/assets/js/196.a6bd7add.js"><link rel="prefetch" href="/assets/js/20.4e91cd31.js"><link rel="prefetch" href="/assets/js/21.f095e6e1.js"><link rel="prefetch" href="/assets/js/22.72f4b8ab.js"><link rel="prefetch" href="/assets/js/23.e94eb9d2.js"><link rel="prefetch" href="/assets/js/24.0eae7d6f.js"><link rel="prefetch" href="/assets/js/25.36157609.js"><link rel="prefetch" href="/assets/js/26.dc5b6cba.js"><link rel="prefetch" href="/assets/js/27.c19b7b63.js"><link rel="prefetch" href="/assets/js/28.3aceae59.js"><link rel="prefetch" href="/assets/js/29.536091b3.js"><link rel="prefetch" href="/assets/js/3.d11119c4.js"><link rel="prefetch" href="/assets/js/30.821a4a30.js"><link rel="prefetch" href="/assets/js/31.5238784c.js"><link rel="prefetch" href="/assets/js/32.10bc7179.js"><link rel="prefetch" href="/assets/js/33.c1ed69c9.js"><link rel="prefetch" href="/assets/js/34.8d384231.js"><link rel="prefetch" href="/assets/js/35.d8890e52.js"><link rel="prefetch" href="/assets/js/36.eca37ad5.js"><link rel="prefetch" href="/assets/js/37.802549e3.js"><link rel="prefetch" href="/assets/js/38.53841770.js"><link rel="prefetch" href="/assets/js/39.7ae44409.js"><link rel="prefetch" href="/assets/js/4.493b9bca.js"><link rel="prefetch" href="/assets/js/40.ce56364a.js"><link rel="prefetch" href="/assets/js/41.85f0114b.js"><link rel="prefetch" href="/assets/js/42.714da6e2.js"><link rel="prefetch" href="/assets/js/43.fee4437c.js"><link rel="prefetch" href="/assets/js/44.b039b68b.js"><link rel="prefetch" href="/assets/js/45.96a55605.js"><link rel="prefetch" href="/assets/js/46.956ffb03.js"><link rel="prefetch" href="/assets/js/47.147d9218.js"><link rel="prefetch" href="/assets/js/48.ff787b40.js"><link rel="prefetch" href="/assets/js/49.871eee87.js"><link rel="prefetch" href="/assets/js/5.e0ba07d7.js"><link rel="prefetch" href="/assets/js/50.99b7c29e.js"><link rel="prefetch" href="/assets/js/51.8ecbf4ba.js"><link rel="prefetch" href="/assets/js/52.53d91d7e.js"><link rel="prefetch" href="/assets/js/53.af8a0d2a.js"><link rel="prefetch" href="/assets/js/54.a2f848b5.js"><link rel="prefetch" href="/assets/js/55.267e9947.js"><link rel="prefetch" href="/assets/js/56.0b201c40.js"><link rel="prefetch" href="/assets/js/57.cbdfd6f7.js"><link rel="prefetch" href="/assets/js/58.636c0c3f.js"><link rel="prefetch" href="/assets/js/59.fc9216c4.js"><link rel="prefetch" href="/assets/js/6.b98373f2.js"><link rel="prefetch" href="/assets/js/60.34f16fc4.js"><link rel="prefetch" href="/assets/js/61.4d130bd8.js"><link rel="prefetch" href="/assets/js/62.927caa10.js"><link rel="prefetch" href="/assets/js/63.a451fee0.js"><link rel="prefetch" href="/assets/js/64.32a5d47b.js"><link rel="prefetch" href="/assets/js/65.bc099429.js"><link rel="prefetch" href="/assets/js/66.3953050d.js"><link rel="prefetch" href="/assets/js/67.e934823b.js"><link rel="prefetch" href="/assets/js/68.4bcb52b0.js"><link rel="prefetch" href="/assets/js/69.bede18c8.js"><link rel="prefetch" href="/assets/js/7.8de8df2d.js"><link rel="prefetch" href="/assets/js/70.fce1daac.js"><link rel="prefetch" href="/assets/js/71.ea0a8c5d.js"><link rel="prefetch" href="/assets/js/72.15382c9e.js"><link rel="prefetch" href="/assets/js/73.848364d3.js"><link rel="prefetch" href="/assets/js/74.5fd08a50.js"><link rel="prefetch" href="/assets/js/75.c937c70d.js"><link rel="prefetch" href="/assets/js/76.a0dacd5a.js"><link rel="prefetch" href="/assets/js/77.4019cc23.js"><link rel="prefetch" href="/assets/js/78.9676a9e1.js"><link rel="prefetch" href="/assets/js/79.e46e10d5.js"><link rel="prefetch" href="/assets/js/8.2098eb96.js"><link rel="prefetch" href="/assets/js/80.987e83cb.js"><link rel="prefetch" href="/assets/js/81.eb98ff36.js"><link rel="prefetch" href="/assets/js/82.623561a7.js"><link rel="prefetch" href="/assets/js/83.e256d909.js"><link rel="prefetch" href="/assets/js/84.7d06a550.js"><link rel="prefetch" href="/assets/js/85.b8d9879e.js"><link rel="prefetch" href="/assets/js/86.31c4581b.js"><link rel="prefetch" href="/assets/js/87.e06ee05e.js"><link rel="prefetch" href="/assets/js/88.81ef718d.js"><link rel="prefetch" href="/assets/js/89.ba237d2f.js"><link rel="prefetch" href="/assets/js/9.36092fd0.js"><link rel="prefetch" href="/assets/js/90.ad2c9d92.js"><link rel="prefetch" href="/assets/js/92.1c28035b.js"><link rel="prefetch" href="/assets/js/93.c8b8e3d6.js"><link rel="prefetch" href="/assets/js/94.b6bc4a44.js"><link rel="prefetch" href="/assets/js/95.92cea882.js"><link rel="prefetch" href="/assets/js/96.5373491b.js"><link rel="prefetch" href="/assets/js/97.bb39efc8.js"><link rel="prefetch" href="/assets/js/98.af7a030f.js"><link rel="prefetch" href="/assets/js/99.07dc87d8.js">
    <link rel="stylesheet" href="/assets/css/0.styles.d9c8cf8c.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="https://lingxin-tanhua.oss-cn-shanghai.aliyuncs.com/QQ%E6%88%AA%E5%9B%BE20220503092755.png" alt="凌歆的博客" class="logo"> <span class="site-name can-hide">凌歆的博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><a href="/web/" class="link-title">前端</a> <span class="title" style="display:none;">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>学习笔记</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/html/" class="nav-link">HTML笔记</a></li><li class="dropdown-subitem"><a href="/note/js-low/" class="nav-link">JavaScript基础笔记</a></li><li class="dropdown-subitem"><a href="/note/js-high/" class="nav-link">JavaScript高阶笔记</a></li><li class="dropdown-subitem"><a href="/note/js-dom-bom/" class="nav-link">JavaScript DOM和BOM笔记</a></li><li class="dropdown-subitem"><a href="/note/jquery/" class="nav-link">jQuery笔记</a></li><li class="dropdown-subitem"><a href="/note/ajax/" class="nav-link">Ajax笔记</a></li><li class="dropdown-subitem"><a href="/note/nodejs/" class="nav-link">NodeJs笔记</a></li><li class="dropdown-subitem"><a href="/note/reg/" class="nav-link">正则表达式笔记</a></li><li class="dropdown-subitem"><a href="/note/vue/" class="nav-link">Vue笔记</a></li><li class="dropdown-subitem"><a href="/note/react/" class="nav-link">react笔记</a></li><li class="dropdown-subitem"><a href="/note/wx/" class="nav-link">微信小程序笔记</a></li><li class="dropdown-subitem"><a href="/note/uniapp/" class="nav-link">uniapp笔记</a></li><li class="dropdown-subitem"><a href="/note/echarts/" class="nav-link">echarts笔记</a></li><li class="dropdown-subitem"><a href="/note/git/" class="nav-link">Git笔记</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="后端" class="dropdown-title"><a href="/back/" class="link-title">后端</a> <span class="title" style="display:none;">后端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/java/" class="nav-link">JAVA</a></li><li class="dropdown-item"><!----> <a href="/note/javaweb/" class="nav-link">JavaWeb</a></li><li class="dropdown-item"><!----> <a href="/note/mysql/" class="nav-link">MySql</a></li><li class="dropdown-item"><!----> <a href="/note/ssm/" class="nav-link">ssm</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="算法" class="dropdown-title"><a href="/algor/" class="link-title">算法</a> <span class="title" style="display:none;">算法</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/sf/" class="nav-link">算法训练营</a></li><li class="dropdown-item"><!----> <a href="/note/js-sf/" class="nav-link">js数据结构与算法</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="面试" class="dropdown-title"><a href="/mianshi/" class="link-title">面试</a> <span class="title" style="display:none;">面试</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/lqb/" class="nav-link">蓝桥杯备战</a></li><li class="dropdown-item"><!----> <a href="/note/ms/" class="nav-link">前端面试</a></li><li class="dropdown-item"><!----> <a href="/note/hmms/" class="nav-link">黑马面试</a></li><li class="dropdown-item"><!----> <a href="/note/xzms/" class="nav-link">校招零距离面试</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="解决方案" class="dropdown-title"><a href="/resolve/" class="link-title">解决方案</a> <span class="title" style="display:none;">解决方案</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/qd-resolve/" class="nav-link">前端解决方案</a></li><li class="dropdown-item"><!----> <a href="/note/hd-resolve/" class="nav-link">后端解决方案</a></li></ul></div></div><div class="nav-item"><a href="/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/linxin1123/vuepress-blog" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://lingxin-tanhua.oss-cn-shanghai.aliyuncs.com/QQ%E6%88%AA%E5%9B%BE20220503092755.png"> <div class="blogger-info"><h3>lingxin</h3> <span>凌歆</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><a href="/web/" class="link-title">前端</a> <span class="title" style="display:none;">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>学习笔记</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/html/" class="nav-link">HTML笔记</a></li><li class="dropdown-subitem"><a href="/note/js-low/" class="nav-link">JavaScript基础笔记</a></li><li class="dropdown-subitem"><a href="/note/js-high/" class="nav-link">JavaScript高阶笔记</a></li><li class="dropdown-subitem"><a href="/note/js-dom-bom/" class="nav-link">JavaScript DOM和BOM笔记</a></li><li class="dropdown-subitem"><a href="/note/jquery/" class="nav-link">jQuery笔记</a></li><li class="dropdown-subitem"><a href="/note/ajax/" class="nav-link">Ajax笔记</a></li><li class="dropdown-subitem"><a href="/note/nodejs/" class="nav-link">NodeJs笔记</a></li><li class="dropdown-subitem"><a href="/note/reg/" class="nav-link">正则表达式笔记</a></li><li class="dropdown-subitem"><a href="/note/vue/" class="nav-link">Vue笔记</a></li><li class="dropdown-subitem"><a href="/note/react/" class="nav-link">react笔记</a></li><li class="dropdown-subitem"><a href="/note/wx/" class="nav-link">微信小程序笔记</a></li><li class="dropdown-subitem"><a href="/note/uniapp/" class="nav-link">uniapp笔记</a></li><li class="dropdown-subitem"><a href="/note/echarts/" class="nav-link">echarts笔记</a></li><li class="dropdown-subitem"><a href="/note/git/" class="nav-link">Git笔记</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="后端" class="dropdown-title"><a href="/back/" class="link-title">后端</a> <span class="title" style="display:none;">后端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/java/" class="nav-link">JAVA</a></li><li class="dropdown-item"><!----> <a href="/note/javaweb/" class="nav-link">JavaWeb</a></li><li class="dropdown-item"><!----> <a href="/note/mysql/" class="nav-link">MySql</a></li><li class="dropdown-item"><!----> <a href="/note/ssm/" class="nav-link">ssm</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="算法" class="dropdown-title"><a href="/algor/" class="link-title">算法</a> <span class="title" style="display:none;">算法</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/sf/" class="nav-link">算法训练营</a></li><li class="dropdown-item"><!----> <a href="/note/js-sf/" class="nav-link">js数据结构与算法</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="面试" class="dropdown-title"><a href="/mianshi/" class="link-title">面试</a> <span class="title" style="display:none;">面试</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/lqb/" class="nav-link">蓝桥杯备战</a></li><li class="dropdown-item"><!----> <a href="/note/ms/" class="nav-link">前端面试</a></li><li class="dropdown-item"><!----> <a href="/note/hmms/" class="nav-link">黑马面试</a></li><li class="dropdown-item"><!----> <a href="/note/xzms/" class="nav-link">校招零距离面试</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="解决方案" class="dropdown-title"><a href="/resolve/" class="link-title">解决方案</a> <span class="title" style="display:none;">解决方案</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/note/qd-resolve/" class="nav-link">前端解决方案</a></li><li class="dropdown-item"><!----> <a href="/note/hd-resolve/" class="nav-link">后端解决方案</a></li></ul></div></div><div class="nav-item"><a href="/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/linxin1123/vuepress-blog" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>学习笔记</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Java笔记</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>JavaWeb笔记</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>MySql笔记</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/533d88/" aria-current="page" class="active sidebar-link">mysql学习第一天</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/533d88/#_1-mysql-的安装" class="sidebar-link">1. Mysql 的安装</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_1-2-启动-mysql-服务" class="sidebar-link">1.2 启动 MySQL 服务</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_1-3-mysql-的登录和退出-cmd-命令行窗口" class="sidebar-link">1.3 MySQL 的登录和退出(cmd 命令行窗口)</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/533d88/#_2-sql" class="sidebar-link">2.SQL</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_2-1-sql-的作用" class="sidebar-link">2.1 SQL 的作用</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_2-2-sql-语句类别" class="sidebar-link">2.2 SQL 语句类别</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_2-3-sql-的语法规范" class="sidebar-link">2.3 SQL 的语法规范</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/533d88/#_3-ddl-操作数据库-表" class="sidebar-link">3.DDL(操作数据库，表)</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_3-1-操作数据库-crud" class="sidebar-link">3.1 操作数据库：CRUD</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#r-1-查看所有数据库的名称" class="sidebar-link">R.1: 查看所有数据库的名称</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#r-2-查看某个数据库的字符集-查看某个数据库的创建语句" class="sidebar-link">R.2:查看某个数据库的字符集（查看某个数据库的创建语句）</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#c-1-创建一个数据库" class="sidebar-link">C.1 创建一个数据库</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#c-2-创建一个数据库-看数据库名是否存在-存在才创建" class="sidebar-link">C.2 创建一个数据库（看数据库名是否存在，存在才创建）</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#c-3-创建一个数据库以-gbk-为编码" class="sidebar-link">C.3 创建一个数据库以 gbk 为编码</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#u-1-修改数据库的字符集" class="sidebar-link">U.1 修改数据库的字符集</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#d-1-删除数据库-判断是否存在-存在再删除" class="sidebar-link">D.1 删除数据库（判断是否存在，存在再删除）</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#使用数据库" class="sidebar-link">使用数据库</a></li><li class="sidebar-sub-header level4"><a href="/pages/533d88/#_1-查询当前正在使用的数据库名称" class="sidebar-link">1. 查询当前正在使用的数据库名称</a></li><li class="sidebar-sub-header level4"><a href="/pages/533d88/#_2-使用数据库-进入数据库" class="sidebar-link">2. 使用数据库（进入数据库）</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/533d88/#_4-ddl-操作表" class="sidebar-link">4.DDL:操作表</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/533d88/#r-1-查询某个数据库中所有的表的名称" class="sidebar-link">R.1 查询某个数据库中所有的表的名称</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#r-2-查询某个表中的结构" class="sidebar-link">R.2 查询某个表中的结构</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#c-1-创建表" class="sidebar-link">C.1 创建表</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#常用的数据类型" class="sidebar-link">常用的数据类型</a></li><li class="sidebar-sub-header level4"><a href="/pages/533d88/#注意点" class="sidebar-link">注意点</a></li><li class="sidebar-sub-header level4"><a href="/pages/533d88/#示例" class="sidebar-link">示例</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#c-2-复制一个相同的表" class="sidebar-link">C.2 复制一个相同的表</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#d-1-删除表" class="sidebar-link">D.1 删除表</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#u-1-修改表名" class="sidebar-link">U.1 修改表名</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#r-1-查看一个表的字符集" class="sidebar-link">R.1 查看一个表的字符集</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#r-3-修改一个表的字符集" class="sidebar-link">R.3 修改一个表的字符集</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#u-2-表中添加一列" class="sidebar-link">U.2 表中添加一列</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#u-3-修改列的名称-数据类型" class="sidebar-link">U.3 修改列的名称，数据类型</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#d-2-删除表中的某一列" class="sidebar-link">D.2 删除表中的某一列</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/533d88/#_5-dml-增删改表中记录" class="sidebar-link">5.DML(增删改表中记录)</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_5-1-添加数据" class="sidebar-link">5.1 添加数据</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_5-2-删除数据" class="sidebar-link">5.2 删除数据</a></li><li class="sidebar-sub-header level4"><a href="/pages/533d88/#注意点-2" class="sidebar-link">注意点</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_5-3-修改数据" class="sidebar-link">5.3 修改数据</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/533d88/#_6-查询表中的记录-dql" class="sidebar-link">6. 查询表中的记录（DQL）</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_6-1-基础查询" class="sidebar-link">6.1 基础查询</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_6-2-多个字段的查询" class="sidebar-link">6.2 多个字段的查询</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_6-3-去除重复的结果集" class="sidebar-link">6.3 去除重复的结果集</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_6-4-计算列的和" class="sidebar-link">6.4 计算列的和</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_6-5-起别名" class="sidebar-link">6.5 起别名</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/533d88/#_7-dql-条件查询" class="sidebar-link">7.DQL(条件查询)</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_7-1-查询关系表达式" class="sidebar-link">7.1 查询关系表达式（&gt;,&lt;,=....）</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_7-2-between-and-查询" class="sidebar-link">7.2 between...and...查询</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_7-3-or-或者-和-in-集合" class="sidebar-link">7.3 or 或者 || 和 IN（集合）</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_7-4-is-null-和-is-not-null" class="sidebar-link">7.4 is null 和 is not null</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_7-5-like-模糊查询" class="sidebar-link">7.5 like(模糊查询)</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/533d88/#_8-总结" class="sidebar-link">8.总结</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_8-1-数据库的操作" class="sidebar-link">8.1 数据库的操作</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_8-2-库中表的操作" class="sidebar-link">8.2 库中表的操作</a></li><li class="sidebar-sub-header level3"><a href="/pages/533d88/#_8-3-表中数据的操作" class="sidebar-link">8.3 表中数据的操作</a></li></ul></li></ul></li><li><a href="/pages/e13f8c/" class="sidebar-link">MySQL学习第二天</a></li><li><a href="/pages/774997/" class="sidebar-link">MySql学习第三天</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>SSM笔记</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><a href="/back/#后端" data-v-06225672>后端</a></li><li data-v-06225672><a href="/back/#MySql笔记" data-v-06225672>MySql笔记</a></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/linxin1123" target="_blank" title="作者" class="beLink" data-v-06225672>lingxin</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2023-01-25</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">mysql学习第一天<!----></h1>  <div class="theme-vdoing-content content__default"><h1 id="mysql-第一天"><a href="#mysql-第一天" class="header-anchor">#</a> mysql 第一天</h1> <p>@[toc]</p> <h2 id="_1-mysql-的安装"><a href="#_1-mysql-的安装" class="header-anchor">#</a> 1. Mysql 的安装</h2> <ul><li><strong>安装成功后的 datadir 目录</strong></li></ul> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token assign-left variable">datadir</span><span class="token operator">=</span><span class="token string">&quot;C:/ProgramData/MySQL/MySQL Server 5.5/Data/&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li><strong>卸载完成后需要将该文件夹删除</strong></li></ul> <h3 id="_1-2-启动-mysql-服务"><a href="#_1-2-启动-mysql-服务" class="header-anchor">#</a> 1.2 启动 MySQL 服务</h3> <ul><li><p>计算机-&gt;管理-&gt;服务</p></li> <li><p>cmd-&gt;services.msc 打开</p></li> <li><p><strong>cmd-&gt;net start mysql (需要系统管理员权限)</strong></p> <ul><li>以管理员的身份打开 cmd 窗口</li></ul></li></ul> <p><img src="https://img-blog.csdnimg.cn/03d20d96b6164beeb35e1a64a48156c2.png#pic_center" alt="在这里插入图片描述"></p> <h3 id="_1-3-mysql-的登录和退出-cmd-命令行窗口"><a href="#_1-3-mysql-的登录和退出-cmd-命令行窗口" class="header-anchor">#</a> 1.3 MySQL 的登录和退出(cmd 命令行窗口)</h3> <ul><li>登录</li></ul> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>mysql <span class="token parameter variable">-uroot</span> <span class="token parameter variable">-proot</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>退出</li></ul> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token builtin class-name">exit</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>登录其他主机上的数据库</li></ul> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>mysql -h<span class="token punctuation">(</span>ip地址<span class="token punctuation">)</span> <span class="token parameter variable">-uroot</span> <span class="token parameter variable">-proot</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="language-shell line-numbers-mode"><pre class="language-shell"><code>mysql <span class="token parameter variable">--host</span><span class="token operator">=</span>ip地址 <span class="token parameter variable">--user</span><span class="token operator">=</span>root <span class="token parameter variable">--password</span><span class="token operator">=</span>root
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="_2-sql"><a href="#_2-sql" class="header-anchor">#</a> 2.SQL</h2> <ul><li>定义：<strong>SQL（Structured Query Language）：结构化查询语言</strong></li></ul> <h3 id="_2-1-sql-的作用"><a href="#_2-1-sql-的作用" class="header-anchor">#</a> 2.1 SQL 的作用</h3> <ul><li><strong>所有关系型数据库的查询规范，不同数据库都支持</strong></li> <li><strong>通用数据库操作语言，可以用于不同数据库系统</strong></li> <li><strong>不同的数据库 SQL 有一定区别</strong></li></ul> <h3 id="_2-2-sql-语句类别"><a href="#_2-2-sql-语句类别" class="header-anchor">#</a> 2.2 SQL 语句类别</h3> <ul><li><p><strong>DDL（数据定义语言）：例如:建库，建表</strong></p></li> <li><p><strong>DML（数据操纵语言）：例如:对表中的记录增删改</strong></p></li> <li><p><strong>DQL（数据查询语言）：例如：对表中的查询操作</strong></p></li> <li><p><strong>DCL（数据控制语言）：例如：对用户权限控制</strong></p></li> <li><p>图解</p></li></ul> <p><img src="https://img-blog.csdnimg.cn/10f6f5f6fc874cf0afc79d67e8a9ea4e.bmp?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="_2-3-sql-的语法规范"><a href="#_2-3-sql-的语法规范" class="header-anchor">#</a> 2.3 SQL 的语法规范</h3> <ul><li><p><strong>语句以分号结尾</strong></p></li> <li><p><strong>不区分大小写</strong></p></li> <li><p><strong>3 种注释</strong></p> <table><thead><tr><th>注释的语法</th> <th>说明</th></tr></thead> <tbody><tr><td>--空格</td> <td>单行注释</td></tr> <tr><td>/**/</td> <td>多行注释</td></tr> <tr><td>#</td> <td>MySQL 的特有注释</td></tr></tbody></table></li> <li><p>图解</p></li></ul> <p><img src="https://img-blog.csdnimg.cn/57084541c11a4c5e8fd74f584a891570.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_17,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <p><img src="https://img-blog.csdnimg.cn/beab958afc86412b9ae47f3830d52d7a.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_16,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <p><img src="https://img-blog.csdnimg.cn/5db8936c1fbe4e75acdc31a145e10e31.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_17,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h2 id="_3-ddl-操作数据库-表"><a href="#_3-ddl-操作数据库-表" class="header-anchor">#</a> 3.DDL(操作数据库，表)</h2> <h3 id="_3-1-操作数据库-crud"><a href="#_3-1-操作数据库-crud" class="header-anchor">#</a> 3.1 操作数据库：CRUD</h3> <ul><li>C(Create):创建</li> <li>R(Retrieve):查询</li> <li>U(Update):改</li> <li>D(Delete):删</li> <li>使用数据库</li></ul> <h3 id="r-1-查看所有数据库的名称"><a href="#r-1-查看所有数据库的名称" class="header-anchor">#</a> R.1: 查看所有数据库的名称</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">show</span> <span class="token keyword">databases</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="r-2-查看某个数据库的字符集-查看某个数据库的创建语句"><a href="#r-2-查看某个数据库的字符集-查看某个数据库的创建语句" class="header-anchor">#</a> R.2:查看某个数据库的字符集（查看某个数据库的创建语句）</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">show</span> creat <span class="token keyword">database</span> mysql（数据库名称）<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/362762117816485fb048f3855042c03a.png#pic_center" alt="在这里插入图片描述"></p> <h3 id="c-1-创建一个数据库"><a href="#c-1-创建一个数据库" class="header-anchor">#</a> C.1 创建一个数据库</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code>creat <span class="token keyword">database</span> db1<span class="token punctuation">(</span>数据库名称<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/a52b8ee690984a248b496bfe5f5c0952.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="c-2-创建一个数据库-看数据库名是否存在-存在才创建"><a href="#c-2-创建一个数据库-看数据库名是否存在-存在才创建" class="header-anchor">#</a> C.2 创建一个数据库（看数据库名是否存在，存在才创建）</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">create</span> <span class="token keyword">database</span> <span class="token keyword">if</span> <span class="token operator">not</span> <span class="token keyword">exists</span> db1<span class="token punctuation">(</span>数据库名<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/7eb4c97c2ae14a188c6e7b6a3a696615.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="c-3-创建一个数据库以-gbk-为编码"><a href="#c-3-创建一个数据库以-gbk-为编码" class="header-anchor">#</a> C.3 创建一个数据库以 gbk 为编码</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">CREATE</span> <span class="token keyword">DATABASE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> db4 <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> gbk<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/12e0ed62414540d8898c41b2f024086d.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="u-1-修改数据库的字符集"><a href="#u-1-修改数据库的字符集" class="header-anchor">#</a> U.1 修改数据库的字符集</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">alter</span> <span class="token keyword">database</span> 数据库名称 <span class="token keyword">character</span> <span class="token keyword">set</span> 字符集名称<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/8e5d6d6d2ea64f688b610a7a27d7a4ff.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="d-1-删除数据库-判断是否存在-存在再删除"><a href="#d-1-删除数据库-判断是否存在-存在再删除" class="header-anchor">#</a> D.1 删除数据库（判断是否存在，存在再删除）</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">drop</span> <span class="token keyword">database</span> <span class="token keyword">if</span> <span class="token keyword">exists</span> db4<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/5fb914920f484468a0a64bd7859fc06b.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="使用数据库"><a href="#使用数据库" class="header-anchor">#</a> 使用数据库</h3> <h4 id="_1-查询当前正在使用的数据库名称"><a href="#_1-查询当前正在使用的数据库名称" class="header-anchor">#</a> 1. 查询当前正在使用的数据库名称</h4> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">select</span> <span class="token keyword">database</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/e47d5e216411443484b99ce5cdd716d1.png#pic_center" alt="在这里插入图片描述"></p> <h4 id="_2-使用数据库-进入数据库"><a href="#_2-使用数据库-进入数据库" class="header-anchor">#</a> 2. 使用数据库（进入数据库）</h4> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">use</span> 数据库名称<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/eaed3ba8da8b4f90bcbf4e9daee39a87.png#pic_center" alt="在这里插入图片描述"></p> <h2 id="_4-ddl-操作表"><a href="#_4-ddl-操作表" class="header-anchor">#</a> 4.DDL:操作表</h2> <h3 id="r-1-查询某个数据库中所有的表的名称"><a href="#r-1-查询某个数据库中所有的表的名称" class="header-anchor">#</a> R.1 查询某个数据库中所有的表的名称</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">show</span> <span class="token keyword">tables</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/05cb004a63e44b32b88e582c94b4370a.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_17,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="r-2-查询某个表中的结构"><a href="#r-2-查询某个表中的结构" class="header-anchor">#</a> R.2 查询某个表中的结构</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">desc</span> 表的名称<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/b1e01e27b9314f39805569638810d8a7.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="c-1-创建表"><a href="#c-1-创建表" class="header-anchor">#</a> C.1 创建表</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">create</span> <span class="token keyword">table</span> 表名{
	字段名<span class="token number">1</span> 字段类型<span class="token punctuation">,</span>
	字段名<span class="token number">2</span> 字段类型<span class="token punctuation">,</span>
	<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
	字段名n 字段类型
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h3 id="常用的数据类型"><a href="#常用的数据类型" class="header-anchor">#</a> 常用的数据类型</h3> <table><thead><tr><th>类型</th> <th>语法</th> <th>示例</th></tr></thead> <tbody><tr><td>整数（int）</td> <td>int</td> <td>age int,</td></tr> <tr><td>小数（double）</td> <td>double</td> <td>score double(5,2),表示最大长度为 5，保留 2 位小数</td></tr> <tr><td>日期(date)</td> <td>date</td> <td>atime date,取值为 yyyy-MM-dd</td></tr> <tr><td>日期（datetime）</td> <td>datetime</td> <td>atime datetime,取值为 yyyy-MM-dd HH:mm:ss,</td></tr> <tr><td>时间戳类型(timestamp)</td> <td>timestamp</td> <td>atime timestamp,取值为 yyyy-MM-dd HH:mm:ss,</td></tr> <tr><td>字符串类型(varchar)</td> <td>varchar()</td> <td>name varchar(8),8 代表最大字符为 8</td></tr></tbody></table> <h4 id="注意点"><a href="#注意点" class="header-anchor">#</a> 注意点</h4> <ul><li><strong>时间戳类型如果不给这个字段赋值，或赋值为 null,则默认使用当前系统时间，来自动赋值</strong></li></ul> <h4 id="示例"><a href="#示例" class="header-anchor">#</a> 示例</h4> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">create</span> <span class="token keyword">table</span> student<span class="token punctuation">(</span>
	id <span class="token keyword">int</span><span class="token punctuation">,</span>
	age <span class="token keyword">int</span><span class="token punctuation">,</span>
	score <span class="token keyword">double</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
	birthday <span class="token keyword">date</span><span class="token punctuation">,</span>
	insert_time <span class="token keyword">timestamp</span>
<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/44abd2420f274b16a421a6cb4a495a07.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="c-2-复制一个相同的表"><a href="#c-2-复制一个相同的表" class="header-anchor">#</a> C.2 复制一个相同的表</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">create</span> <span class="token keyword">table</span> stu <span class="token operator">like</span> student<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/f512a8bd274240cf91785a3253581503.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="d-1-删除表"><a href="#d-1-删除表" class="header-anchor">#</a> D.1 删除表</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">drop</span> <span class="token keyword">table</span> <span class="token keyword">if</span> <span class="token keyword">exists</span> 表名<span class="token punctuation">;</span>
<span class="token keyword">drop</span> <span class="token keyword">table</span> 表名<span class="token punctuation">;</span> <span class="token comment">-- 也可以</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/b1b26f7c4e1d44f6bb48f6733acfaa5a.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="u-1-修改表名"><a href="#u-1-修改表名" class="header-anchor">#</a> U.1 修改表名</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">alter</span> <span class="token keyword">table</span> 表名 <span class="token keyword">rename</span> <span class="token keyword">to</span> 新的表名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/cf42b7a5765240f3810575193c413a43.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="r-1-查看一个表的字符集"><a href="#r-1-查看一个表的字符集" class="header-anchor">#</a> R.1 查看一个表的字符集</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">show</span> <span class="token keyword">create</span> <span class="token keyword">table</span> 表名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/94d2a147e2f6425ab249ceaed11913a5.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="r-3-修改一个表的字符集"><a href="#r-3-修改一个表的字符集" class="header-anchor">#</a> R.3 修改一个表的字符集</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">alter</span> <span class="token keyword">table</span> 表名 <span class="token keyword">character</span> <span class="token keyword">set</span> 字符集的名称<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/301fee42b30e4e41b66f1246aea59bc4.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="u-2-表中添加一列"><a href="#u-2-表中添加一列" class="header-anchor">#</a> U.2 表中添加一列</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code> <span class="token keyword">alter</span> <span class="token keyword">table</span> stu <span class="token keyword">add</span> 列名 数据类型
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/096aaa0b1a7d46c48a45e24ffd94bf0d.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="u-3-修改列的名称-数据类型"><a href="#u-3-修改列的名称-数据类型" class="header-anchor">#</a> U.3 修改列的名称，数据类型</h3> <ul><li>修改列的名称和数据类型</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">alter</span> <span class="token keyword">table</span> 表名 change 列名 新列名 新数据类型<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/b120dd0a0c7e43afb829ddb945854bb5.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>修改列的数据类型</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">alter</span> <span class="token keyword">table</span> 表名 <span class="token keyword">modify</span> 列名 新数据类型<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/628555df2d864bcb86bee33e804bc206.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="d-2-删除表中的某一列"><a href="#d-2-删除表中的某一列" class="header-anchor">#</a> D.2 删除表中的某一列</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">alter</span> <span class="token keyword">table</span> 表名 <span class="token keyword">drop</span> 列名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/e826172bd3bc4e9398f7861eb037bd7f.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h2 id="_5-dml-增删改表中记录"><a href="#_5-dml-增删改表中记录" class="header-anchor">#</a> 5.DML(增删改表中记录)</h2> <h3 id="_5-1-添加数据"><a href="#_5-1-添加数据" class="header-anchor">#</a> 5.1 添加数据</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">insert</span> <span class="token keyword">into</span> 表名<span class="token punctuation">(</span>列名<span class="token number">1</span>，列名<span class="token number">2</span>，列名<span class="token number">3.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>列名n<span class="token punctuation">)</span> <span class="token keyword">values</span><span class="token punctuation">(</span>值<span class="token number">1</span>，值<span class="token number">2</span>，值<span class="token number">3.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>值n<span class="token punctuation">)</span>


<span class="token comment">-- 方法二（全部赋值的简化写法）</span>
<span class="token keyword">insert</span> <span class="token keyword">into</span> 表名 <span class="token keyword">values</span><span class="token punctuation">(</span>值<span class="token number">1</span>，值<span class="token number">2</span>，值<span class="token number">3.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>值n<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/61c476fbb43b49f6937ee117a6ee00e0.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>效果图 2</li></ul> <p><img src="https://img-blog.csdnimg.cn/2dd030c998c7451cb1211f1406bf933f.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="_5-2-删除数据"><a href="#_5-2-删除数据" class="header-anchor">#</a> 5.2 删除数据</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">delete</span> <span class="token keyword">from</span> 表名 <span class="token punctuation">[</span><span class="token keyword">where</span> 条件表达式<span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment">-- 删除满足条件的记录</span>

<span class="token keyword">delete</span> <span class="token keyword">from</span> 表名<span class="token punctuation">;</span><span class="token comment">-- 删除表中所有数据</span>

<span class="token comment">-- 删除表，然后在创建一个一模一样的空表</span>

<span class="token keyword">truncate</span> <span class="token keyword">table</span> 表名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><ul><li>删除满足条件的记录效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/7239bc6f31c24b79bf8b12eb061a680e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>删除所有记录</li></ul> <p><img src="https://img-blog.csdnimg.cn/46637669590f46348b11538ab19edc9a.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h4 id="注意点-2"><a href="#注意点-2" class="header-anchor">#</a> 注意点</h4> <ul><li>第二种方法删除记录不推荐（表中多少记录，执行多少次删除操作，效率低）</li> <li>第三种方法先删除表，再创建表，效率高</li></ul> <h3 id="_5-3-修改数据"><a href="#_5-3-修改数据" class="header-anchor">#</a> 5.3 修改数据</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">update</span> 表名 <span class="token keyword">set</span> 列名<span class="token number">1</span><span class="token operator">=</span>值<span class="token number">1</span><span class="token punctuation">,</span>列名<span class="token number">2</span><span class="token operator">=</span>值<span class="token number">2.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">where</span> 条件
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/ede9eb9ab8744a328e107bc7c125b944.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>如果不加任何条件，则会将表中的所有记录全部修改</li></ul> <p><img src="https://img-blog.csdnimg.cn/9b64791102264bbdadd99082cf26d717.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h2 id="_6-查询表中的记录-dql"><a href="#_6-查询表中的记录-dql" class="header-anchor">#</a> 6. 查询表中的记录（DQL）</h2> <ul><li>查询语法</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">select</span>
	字段列表
<span class="token keyword">from</span>
    表名列表
<span class="token keyword">where</span>
    条件列表
<span class="token keyword">group</span> <span class="token keyword">by</span>
    分组列表
<span class="token keyword">having</span>
    分组之后的条件
<span class="token keyword">order</span> <span class="token keyword">by</span>
    排序
<span class="token keyword">limit</span>
    分页限定
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h3 id="_6-1-基础查询"><a href="#_6-1-基础查询" class="header-anchor">#</a> 6.1 基础查询</h3> <ul><li>多个字段的查询</li> <li>去除重复</li> <li>计算列</li> <li>起别名</li></ul> <h3 id="_6-2-多个字段的查询"><a href="#_6-2-多个字段的查询" class="header-anchor">#</a> 6.2 多个字段的查询</h3> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">select</span> 字段<span class="token number">1</span>，字段<span class="token number">2</span> <span class="token keyword">from</span> 表名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token comment">-- 创建一个表</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> student3 <span class="token punctuation">(</span>
 id <span class="token keyword">INT</span><span class="token punctuation">,</span> <span class="token comment">-- 编号</span>
 NAME <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">-- 姓名</span>
 age <span class="token keyword">INT</span><span class="token punctuation">,</span> <span class="token comment">-- 年龄</span>
 sex <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">-- 性别</span>
 address <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">-- 地址</span>
 math <span class="token keyword">INT</span><span class="token punctuation">,</span> <span class="token comment">-- 数学</span>
 english <span class="token keyword">INT</span> <span class="token comment">-- 英语</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> student3<span class="token punctuation">(</span>id<span class="token punctuation">,</span>NAME<span class="token punctuation">,</span>age<span class="token punctuation">,</span>sex<span class="token punctuation">,</span>address<span class="token punctuation">,</span>math<span class="token punctuation">,</span>english<span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token string">'马云'</span><span class="token punctuation">,</span><span class="token number">55</span><span class="token punctuation">,</span><span class="token string">'男'</span><span class="token punctuation">,</span><span class="token string">'
杭州'</span><span class="token punctuation">,</span><span class="token number">66</span><span class="token punctuation">,</span><span class="token number">78</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">'马化腾'</span><span class="token punctuation">,</span><span class="token number">45</span><span class="token punctuation">,</span><span class="token string">'女'</span><span class="token punctuation">,</span><span class="token string">'深圳'</span><span class="token punctuation">,</span><span class="token number">98</span><span class="token punctuation">,</span><span class="token number">87</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token string">'马景涛'</span><span class="token punctuation">,</span><span class="token number">55</span><span class="token punctuation">,</span><span class="token string">'男'</span><span class="token punctuation">,</span><span class="token string">'香港'</span><span class="token punctuation">,</span><span class="token number">56</span><span class="token punctuation">,</span><span class="token number">77</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token string">'柳岩
'</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token string">'女'</span><span class="token punctuation">,</span><span class="token string">'湖南'</span><span class="token punctuation">,</span><span class="token number">76</span><span class="token punctuation">,</span><span class="token number">65</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token string">'柳青'</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token string">'男'</span><span class="token punctuation">,</span><span class="token string">'湖南'</span><span class="token punctuation">,</span><span class="token number">86</span><span class="token punctuation">,</span><span class="token boolean">NULL</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">,</span><span class="token string">'刘德华'</span><span class="token punctuation">,</span><span class="token number">57</span><span class="token punctuation">,</span><span class="token string">'男'</span><span class="token punctuation">,</span><span class="token string">'香港
'</span><span class="token punctuation">,</span><span class="token number">99</span><span class="token punctuation">,</span><span class="token number">99</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">,</span><span class="token string">'马德'</span><span class="token punctuation">,</span><span class="token number">22</span><span class="token punctuation">,</span><span class="token string">'女'</span><span class="token punctuation">,</span><span class="token string">'香港'</span><span class="token punctuation">,</span><span class="token number">99</span><span class="token punctuation">,</span><span class="token number">99</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">,</span><span class="token string">'德玛西亚'</span><span class="token punctuation">,</span><span class="token number">18</span><span class="token punctuation">,</span><span class="token string">'男'</span><span class="token punctuation">,</span><span class="token string">'南京'</span><span class="token punctuation">,</span><span class="token number">56</span><span class="token punctuation">,</span><span class="token number">65</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">-- 查看表</span>

<span class="token keyword">SELECT</span> <span class="token operator">*</span><span class="token keyword">FROM</span> student3<span class="token punctuation">;</span>


<span class="token comment">-- 多个字段的查询</span>

<span class="token keyword">SELECT</span> NAME<span class="token punctuation">,</span>age <span class="token keyword">FROM</span> student3<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/18b6cf4d9d9d4c98bbff2ab7cd189e4b.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>规范查询</li></ul> <p><img src="https://img-blog.csdnimg.cn/f5b2b5e736a7469290c393d49281a35a.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>通配符查询（全部的字段）</li></ul> <p><img src="https://img-blog.csdnimg.cn/60d26d6f0c624b30844be94c0c6b89f1.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="_6-3-去除重复的结果集"><a href="#_6-3-去除重复的结果集" class="header-anchor">#</a> 6.3 去除重复的结果集</h3> <ul><li>有重复的结果集</li></ul> <p><img src="https://img-blog.csdnimg.cn/73ccc0629d9541afb16d4a4326a8da5e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>去除重复的结果集</li></ul> <p><img src="https://img-blog.csdnimg.cn/7daf7d2c9dfc487aae0f11a5a0e74fa5.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="_6-4-计算列的和"><a href="#_6-4-计算列的和" class="header-anchor">#</a> 6.4 计算列的和</h3> <ul><li>有 null 参与</li></ul> <p><img src="https://img-blog.csdnimg.cn/f682a7f17fb04e7794b9444294ada67c.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>解决于 null 相加为 null 的问题</li></ul> <p><img src="https://img-blog.csdnimg.cn/52dc5f252b2f4717a27beeed6a67f377.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="_6-5-起别名"><a href="#_6-5-起别名" class="header-anchor">#</a> 6.5 起别名</h3> <ul><li>给一个字段另起一个名字</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">select</span> 字段名 <span class="token keyword">as</span> 别名 <span class="token keyword">from</span> 表名
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>示例</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">SELECT</span> NAME <span class="token keyword">AS</span> 姓名<span class="token punctuation">,</span>math <span class="token keyword">AS</span> 数学<span class="token punctuation">,</span>english <span class="token keyword">AS</span> 英语<span class="token punctuation">,</span>math<span class="token operator">+</span>IFNULL<span class="token punctuation">(</span>math<span class="token operator">+</span>english<span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token keyword">AS</span> 总分 <span class="token keyword">FROM</span> student3<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/7087a073530e498eb38b1f0e4dd2aca8.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li><strong>as 可以省略，用空格代替</strong></li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">SELECT</span> NAME 姓名<span class="token punctuation">,</span>math 数学<span class="token punctuation">,</span>english 英语<span class="token punctuation">,</span>math<span class="token operator">+</span>IFNULL<span class="token punctuation">(</span>math<span class="token operator">+</span>english<span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">)</span> 总分 <span class="token keyword">FROM</span> student3<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>效果图</li></ul> <p><img src="https://img-blog.csdnimg.cn/6157e83c616744faa22821ef2aee3414.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h2 id="_7-dql-条件查询"><a href="#_7-dql-条件查询" class="header-anchor">#</a> 7.DQL(条件查询)</h2> <ul><li><strong>where 子句后的运算符</strong></li></ul> <blockquote><p>1.&gt;、&lt;、&lt;=、&gt;=、=、&lt;&gt;</p> <p>2.BETWEEN...AND</p> <p>3.IN(集合)</p> <p>4.LIKE '张%'</p> <p>5.IS NULL</p> <p>6.and 或 &amp;&amp;</p> <p>7.or 或 ||</p> <p>8.not 或 !</p></blockquote> <h3 id="_7-1-查询关系表达式"><a href="#_7-1-查询关系表达式" class="header-anchor">#</a> 7.1 查询关系表达式（&gt;,&lt;,=....）</h3> <ul><li>查询年龄大于等于 20 的记录</li></ul> <p><img src="https://img-blog.csdnimg.cn/6d3c744805974244906118118c90e127.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>等于 20 只需要写一个等号</li></ul> <p><img src="https://img-blog.csdnimg.cn/ec20531bf1914e27980c9139bbc5c2be.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>不等于 20 可以写!=或者&lt;&gt;</li></ul> <p><img src="https://img-blog.csdnimg.cn/13f5253d113346ee977505d1ee7fa520.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <p><img src="https://img-blog.csdnimg.cn/63c7dfddbd84477e94edef9c4edb7462.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="_7-2-between-and-查询"><a href="#_7-2-between-and-查询" class="header-anchor">#</a> 7.2 between...and...查询</h3> <ul><li>查询年龄 20 到 30 之间
<ul><li>&amp;&amp; 连接关系表达式</li> <li>and 连接关系表达式</li> <li><strong>age between 20 and 30</strong></li></ul></li></ul> <p><img src="https://img-blog.csdnimg.cn/c812c881428b4d8ebde953f75eec6a7b.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <p><img src="https://img-blog.csdnimg.cn/df112c65abe54c139e51ff5039464b4c.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <p><img src="https://img-blog.csdnimg.cn/9a54f3eb6be34df48076dd49b36dcc5e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="_7-3-or-或者-和-in-集合"><a href="#_7-3-or-或者-和-in-集合" class="header-anchor">#</a> 7.3 or 或者 || 和 IN（集合）</h3> <ul><li>查询年龄 18，22，25 的人</li></ul> <p><img src="https://img-blog.csdnimg.cn/38d138765fa4468da3c36a33b41193ed.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <p><img src="https://img-blog.csdnimg.cn/9f2d83405508492aa9fca5d972775873.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="_7-4-is-null-和-is-not-null"><a href="#_7-4-is-null-和-is-not-null" class="header-anchor">#</a> 7.4 is null 和 is not null</h3> <ul><li>不能用等号判断值是否为 null</li> <li>需要使用 is null 判断</li></ul> <p><img src="https://img-blog.csdnimg.cn/2ff3cc906a054898942f1e6c31bf108a.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <p><img src="https://img-blog.csdnimg.cn/8e6f103ecde94333a41d737985b8d33e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>判断不为 null 的记录</li></ul> <p><img src="https://img-blog.csdnimg.cn/1e559066d7234f07ad3f427696b56793.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h3 id="_7-5-like-模糊查询"><a href="#_7-5-like-模糊查询" class="header-anchor">#</a> 7.5 like(模糊查询)</h3> <ul><li><p>占位符</p> <ul><li><strong>_ 代表单个字符</strong></li> <li><strong>% 代表多个字符</strong></li></ul></li> <li><p>查询姓马的人的记录</p></li></ul> <p><img src="https://img-blog.csdnimg.cn/c6749d42f0044ff5afc772862940b995.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>查询第二字是‘化’的人的记录</li></ul> <p><img src="https://img-blog.csdnimg.cn/d97ccc1fee4843e0ba53ad9a7490a148.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li>查询姓名为 3 个字的人的记录</li></ul> <p><img src="https://img-blog.csdnimg.cn/2c030461164748b9b87adc70c86b4daf.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <ul><li><strong>查询姓名中包含‘德’的人的记录(常用)</strong></li></ul> <p><img src="https://img-blog.csdnimg.cn/2c0a1c8879a445c3b0fbc8b9ef10f0e1.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YeM5q2G,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center" alt="在这里插入图片描述"></p> <h2 id="_8-总结"><a href="#_8-总结" class="header-anchor">#</a> 8.总结</h2> <h3 id="_8-1-数据库的操作"><a href="#_8-1-数据库的操作" class="header-anchor">#</a> 8.1 数据库的操作</h3> <ul><li>查看所有数据库</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">show</span> <span class="token keyword">databases</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>创建数据库</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">create</span> <span class="token keyword">database</span> 库名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>查看数据库创建数据的语句</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">show</span> <span class="token keyword">create</span> <span class="token keyword">database</span> 库名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>删除数据库</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">drop</span> <span class="token keyword">database</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="_8-2-库中表的操作"><a href="#_8-2-库中表的操作" class="header-anchor">#</a> 8.2 库中表的操作</h3> <ul><li>查看所有表</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">show</span> <span class="token keyword">tables</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>创建表</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">create</span> <span class="token keyword">table</span> student{
	id <span class="token keyword">int</span><span class="token punctuation">,</span>
	name varcha<span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
	age <span class="token keyword">int</span>
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><ul><li>查看表的结构</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">show</span> <span class="token keyword">create</span> <span class="token keyword">table</span> 表名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>查看表的组成,表格形式</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">desc</span> 表名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>删除表</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">drop</span> <span class="token keyword">table</span> 表名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="_8-3-表中数据的操作"><a href="#_8-3-表中数据的操作" class="header-anchor">#</a> 8.3 表中数据的操作</h3> <ul><li>插入数据</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">insert</span> <span class="token keyword">into</span> 表名（列名）<span class="token keyword">values</span><span class="token punctuation">(</span>值<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>修改数据</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">update</span> 表名 <span class="token keyword">set</span> 列名<span class="token operator">=</span>值 <span class="token keyword">where</span> 条件<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>删除数据：删除所有数据</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">delete</span> <span class="token keyword">from</span> 表名 <span class="token keyword">where</span> 条件<span class="token punctuation">;</span>
<span class="token keyword">truncate</span> <span class="token punctuation">[</span><span class="token keyword">table</span><span class="token punctuation">]</span> 表名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li>查询记录
<ul><li>查询所有列</li></ul></li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code>selete <span class="token operator">*</span> <span class="token keyword">from</span> 表名<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>查询时指定别名</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code>selete 字段名 <span class="token keyword">as</span> 别名 <span class="token keyword">from</span> 表名<span class="token punctuation">;</span> <span class="token comment">-- as可以省略</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>去除重复数据</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">distinct</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></div></div>  <div class="page-edit"><div class="edit-link"><a href="https://github.com/linxin1123/vuepress-blog/edit/master/docs/02.后端/43.MySql笔记/01.mysql学习第一天.md" target="_blank" rel="noopener noreferrer">编辑</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023/02/17, 11:29:32</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/ae6292/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">JDBC学习笔记</div></a> <a href="/pages/e13f8c/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">MySQL学习第二天</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/ae6292/" class="prev">JDBC学习笔记</a></span> <span class="next"><a href="/pages/e13f8c/">MySQL学习第二天</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/0b785d/"><div>
            Vuex
            <!----></div></a> <span class="date">03-14</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/c59cc0/"><div>
            Vue响应式原理
            <!----></div></a> <span class="date">03-14</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/83cc7a/"><div>
            Vue虚拟DOM-cnblog
            <!----></div></a> <span class="date">03-14</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="3010733382@qq.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/linxin1123" title="GitHub" target="_blank" class="iconfont icon-github"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2022-2023
    <span>lingxin | <a href="https://github.com/linxin1123/vuepress-blog/blob/master/LICENSE" target="_blank">MIT License</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.57550e13.js" defer></script><script src="/assets/js/2.f014c35f.js" defer></script><script src="/assets/js/91.a661f52d.js" defer></script>
  </body>
</html>
